<?
	$db = GetDefaultConnection();

	$where = " and (T_PRODUCT_TOTAL - T_PRODUCT_TRADE)>0 ";

	$queryarry = array(
		'JBNH_SEQ' => $jseq,
		'T_PRODUCT_ITEM1' => $item1,
		'T_PRODUCT_ITEM2' => $item2,
		'T_PRODUCT_WORKYN' => 'N',
	);

	$query=makeWhereQry($queryarry);

	if ($query != "")
		$where .= " and ". $query;

	$sql = sprintf("SELECT T_PRODUCT_TOTAL - T_PRODUCT_TRADE as STOCK_NUMBER "
					.", (select JBNH_NAME FROM TB_JBNH WHERE JBNH_SEQ=a.JBNH_SEQ) as JBNH_NAME "
					.", (select CODE_NAME FROM TB_CODE WHERE CODE_TYPE='A' AND CODE_CODE1=a.T_PRODUCT_ITEM1 AND CODE_CODE2=0) as ITEM1_NAME "
					.", (select CODE_NAME FROM TB_CODE WHERE CODE_TYPE='A' AND CODE_CODE1=a.T_PRODUCT_ITEM1 AND CODE_CODE2=a.T_PRODUCT_ITEM2) as ITEM2_NAME "
					." FROM TB_PRODUCT_TEMP a where 1=1 %s order by T_PRODUCT_SEQ desc "
					, $where);

	$list = $db->queryList($sql)
?>
<?
	if ($list->getLength() == 0)
	{
?>
                <tr>
                	<td colspan=5>등록된 목록이 없습니다.</td>
                </tr>
<?
	}
	else
	{
		$sum=0;
		while ($list->hasNext())
		{
			$row = & $list->next();
			$jbnh_name = $row->getString('JBNH_NAME');
			$item1_name = $row->getString('ITEM1_NAME');
			$item2_name = $row->getString('ITEM2_NAME');
			$stock_number = $row->getNumber('STOCK_NUMBER');
			$sum += $stock_number;
?>
				<tr>
                	<td></td>
                    <td><?=$jbnh_name?></td>
                    <td><?=$item1_name?></td>
                    <td><?=$item2_name?></td>
                    <td><?=$stock_number?>kg</td>
                </tr>
<?
		}
	}
?>